/**
 * 初始化月份选择框
 */
var init_month_select = function () {
    var select_option = "";
    for (var i = month; i >= month - 5; i--) {
        var currMonth = i;
        if (currMonth < 1) {
            currMonth = 12 + i;
        }
        select_option += "<option value='" + currMonth + "'>" + currMonth + "月</option>";
    }
    ;
    $("#month_select").html(select_option);
};



var reload_hightCharts = function (month) {
    options_column.xAxis.categories = month_arr;
    options_column.series = eval("column_data_arr_"+month);
    options_pie.series =  eval("pie_arr_"+month);;
    $('#container').highcharts(options_column);
    $('#container_next').highcharts(options_pie);
};


var reloadData = function(month){
    var $tpl = $('#table_colnum_data_tpl');
    var source = $tpl.text();
    var template = Handlebars.compile(source);
    var html = template(eval("column_data_"+month));
    $("#table_colnum_data").html(html);

    var $tpl = $('#table_colnum_data_2_tpl');
    var source = $tpl.text();
    var template = Handlebars.compile(source);
    var html = template(eval("column_count_data_"+month));
    $("#table_colnum_data_2").html(html);

    var $tpl = $('#pie_table_tpl');
    var source = $tpl.text();
    var template = Handlebars.compile(source);
    var html = template(eval("pie_data_"+month));
    $("#pie_table").html(html);

    var $tpl = $('#pie_table_2_tpl');
    var source = $tpl.text();
    var template = Handlebars.compile(source);
    var html = template(eval("pie_count_data_"+month));
    $("#pie_table_2").html(html);
};

var changeMonth_search = function () {
    var month_select_val = $("#month_select").val();//获取当前选择的月份
    //改变柱状图x轴的名称数据
    month_arr = new Array;
    for (var i = month_select_val - 5; i <= month_select_val; i++) {
        var currMonth = i;
        if (currMonth < 1) {
            currMonth = 12 + i;
        }
        month_arr.push(currMonth + "月");
    }
    //重新加载两种统计图
    reload_hightCharts(month_select_val);
    //重载表格数据
    reloadData(month_select_val);

}

$(function () {
    var EmpCode = getParamValue('EmpCode');
    $("#emp_code").html(EmpCode);
    init_month_select();
    var month_select_val = $("#month_select").val();
    for (var i = month_select_val - 5; i <= month_select_val; i++) {
        month_arr.push(i + "月");
    };
    $('#container').highcharts(options_column);
    $('#container_next').highcharts(options_pie);

    var month_select_val = $("#month_select").val();
    //重载表格数据
    reloadData(month_select_val);
});
var  navigation = function(code){
    var url = "";
    switch(code)
    {
        case "客户管理":
            url ="../esop/group_list.html";
            break;
        case "业务办理":
            url ="../esop/business_list.html";
            break;
        case "工作管理":
            url ="../esop/tasklog_list.html";
            break;

        case "首页":
            url ="";
            break;
        case "工作提醒":
            url ="../esop/reminder.html";
            break;
        case "公告":
            url ="../esop/bulletin_list.html";
            break;
        case "更多":
            url ="index.html";
            break;
        default:
            url ="";
    }
    if("" == url || url.length == 0 || url == null){
        return false;
    }
    window.location.href=url+"?"+getParams();
};


